package com.laboratory.servicecustomer.workBench.controller;

import com.Laboratory.workBench.pojo.notice;
import com.Laboratory.workBench.service.noticeService;
import com.laboratory.servicecustomer.constant.constantArgs;
import com.laboratory.servicecustomer.utilPojo.comm;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author acok
 * @description:TODO
 * @Date 2022/12/11 18:20
 * @Version 1.0
 */
@Controller
@RequestMapping("/notice")
public class noticeController {
    @DubboReference(interfaceClass = noticeService.class,version = "1.0.0")
    private noticeService noticeService;

          /**
               * @return: 公告列表
               * @param: 无参数
               * @description: 获取系统公告展示到前台Home组件
               * @Author: Acok
               * @mbggenerated 2022/12/29
               */
    @RequiresRoles(value={"users","admin","Root"},logical = Logical.OR)
    @RequiresPermissions(value = {"users:home","admin:home","Root:highest"},logical = Logical.OR)
    @GetMapping("/getNotices")
    @ResponseBody
    public Object getAllNoticesToHome(){
        comm comm=new comm();
        try{
            List<notice> notices = noticeService.getAllNotices();
            comm.setCode(constantArgs.COMMUNITY_SUCCESS_CODE);
            comm.setMessage(constantArgs.COMMUNITY_SUCCESS_MESSAGE);
            comm.setOther(notices);
        }catch (Exception e){
            e.printStackTrace();
            comm.setCode(constantArgs.COMMUNITY_FAIL_CODE);
            comm.setMessage(constantArgs.COMMUNITY_FAIL_MESSAGE);
        }
        return comm;
    }
}
